package com.feinno.urcs.group.http.task;

import com.feinno.sip.address.SipUri;
import com.feinno.urcs.group.pd.task.entity.PdBaseGroupMessageArgs;
import com.feinno.urcs.nai.IMPU;
import com.feinno.urcs.sip.SipConnector;
import com.feinno.urcs.sip.UrcsSipFactory;
import com.feinno.urcs.sipservlet.SipConnectorLoader;
import com.feinno.urcs.sipservlet.uac.RcsPageModeUAC;
import com.feinno.urcs.sipservlet.uac.RcsSipUACArgs;
import com.feinno.urcs.sipservlet.uac.RcsUACFactory;
import org.helium.framework.annotations.FieldSetter;

import java.text.ParseException;

/**
 * Created by wuzhiguo on 15-6-8.
 */
public class PdBaseMessageTask {

    @FieldSetter(loader = SipConnectorLoader.class, value = "${SIP_STACK_AS}")
    private SipConnector connector;
    protected String cscfHost;

    protected RcsPageModeUAC createPageModeUAC(PdBaseGroupMessageArgs baseGroupMessage) throws ParseException {
        IMPU groupIMPU = IMPU.parse(baseGroupMessage.getGroupUri());
        IMPU toIMPU = IMPU.parse(baseGroupMessage.getToUri());
        RcsSipUACArgs uacArgs = new RcsSipUACArgs(groupIMPU, toIMPU);
        SipUri cscfSipUri = (SipUri) UrcsSipFactory.getAddressFactory().createURI(cscfHost);
        RcsPageModeUAC uac = RcsUACFactory.createPageModeUAC(connector, cscfSipUri, uacArgs);
        return uac;
    }
}
